<#-- Created by IntelliJ IDEA.
 User: zxm
 Date: 2017/12/19
 Time: 18:00
 To change this template use File | Settings | File Templates.
 角色管理-->
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>监理单位配置</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport"
        content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>

  <script type="text/javascript" src="${re.contextPath}/plugin/jquery/jquery-3.2.1.min.js"></script>
  <#--  <script type="text/javascript" src="${re.contextPath}/plugin/layui2.2/layui.all.js" charset="utf-8"></script>-->
  <script type="text/javascript" src="${re.contextPath}/plugin/layui/layui.all.js" charset="utf-8"></script>
  <link rel="stylesheet" href="${re.contextPath}/plugin/layui2.2/css/layui.css">
  <link rel="stylesheet" href="${re.contextPath}/plugin/lenos/main.css">
</head>
  <style>
  .layui-table-cell {
    text-align: center;
    font-size:14px;
    padding:0 5px;
    height:auto;
    overflow:visible;
    text-overflow:inherit;
    white-space:normal;
    word-break: break-all;
  }
</style>


<body>
<div class="lenos-search">
  <div class="select">
    名称：
    <div class="layui-inline">
      <input class="layui-input" height="20px" id="fileName" autocomplete="off">
    </div>
    <button class="select-on layui-btn layui-btn-sm"  onclick="search()"><i class="layui-icon"></i>
    </button>
    <button class="layui-btn layui-btn-sm icon-position-button" id="refresh" style="float: right;"
            data-type="reload">
      <i class="layui-icon">ဂ</i>
    </button>
  </div>
</div>
<div class="layui-col-md12" style="height:40px;margin-top:3px;">
    <div class="layui-btn-group">
        <button class="layui-btn layui-btn-normal" data-type="del">
            <i class="layui-icon">&#xe640;</i>删除
        </button>
      <button class="layui-btn layui-btn-normal" data-type="add">
        <i class="layui-icon">&#xe640;</i>添加
      </button>
    </div>
</div>

<table id="logList" class="layui-hide" lay-filter="log"></table>
<script type="text/html" id="toolBar">
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon">&#xe640;</i>删除</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="add"><i class="layui-icon">&#xe640;</i>添加</a>
</script>
<script>
  layui.laytpl.toDateString = function(d, format){
    var date = new Date(d || new Date())
        ,ymd = [
      this.digit(date.getFullYear(), 4)
      ,this.digit(date.getMonth() + 1)
      ,this.digit(date.getDate())
    ]
        ,hms = [
      this.digit(date.getHours())
      ,this.digit(date.getMinutes())
      ,this.digit(date.getSeconds())
    ];

    format = format || 'yyyy-MM-dd HH:mm:ss';

    return format.replace(/yyyy/g, ymd[0])
    .replace(/MM/g, ymd[1])
    .replace(/dd/g, ymd[2])
    .replace(/HH/g, hms[0])
    .replace(/mm/g, hms[1])
    .replace(/ss/g, hms[2]);
  };

  //数字前置补零
  layui.laytpl.digit = function(num, length, end){
    var str = '';
    num = String(num);
    length = length || 2;
    for(var i = num.length; i < length; i++){
      str += '0';
    }
    return num < Math.pow(10, length) ? str + (num|0) : num;
  };

  document.onkeydown = function (e) { // 回车提交表单
    var theEvent = window.event || e;
    var code = theEvent.keyCode || theEvent.which;
    if (code == 13) {
      $(".select .select-on").click();
    }
  }

  layui.use(['layer', 'upload',  'table'], function () {

    upload = layui.upload;
    upload.render({
      elem: '#test7'
      ,url: '/sys/sealManager/addFileSeal' //改成您自己的上传接口
      ,size: 60 //限制文件大小，单位 KB
      ,done: function(res){
        layer.msg('上传成功');
        console.log(res)
      }
    });

  });





  layui.use('table', function () {
    var table = layui.table;
    //方法级渲染
    table.render({
      id: 'logList',
      elem: '#logList',
       url: '/sys/sealManager/queryFileSeal'
      , cols: [[
          {checkbox: true, fixed: true, width: '5%'}
        , {field: 'fileName', title: '名称', width: '40%', sort: true , templet: function (d) {
            return '<img  style="width: 30px;height: 30px;float:left;" src="/plugin/common/images/big.png" onclick="viewImage(\'' + d.id + '\',\'' + d.url + '\')">' + d.fileName + '';
          }}
        , {field: 'fileName', title: '图片', width: '20%', sort: true , templet: function (d) {
            return '<img height="anto"  width="150px" src="/supervisor/projectManager/img?fid=' + d.id + '">';
          }}
        , {field: 'createDate', title: '操作时间', width: '30%',templet: '<div>{{ layui.laytpl.toDateString(d.createDate,"yyyy-MM-dd HH:mm:ss") }}</div>'}

      ]]
      , page: true,
      done(res){
        $(".layui-table-header  tr").resize(function () {
          $(".layui-table-header  tr").each(function (index, val) {
            $($(".layui-table-fixed .layui-table-header table tr")[index]).height($(val).height());
          });
        });
        //初始化高度，使得冻结行表头高度一致
        $(".layui-table-header  tr").each(function (index, val) {
          $($(".layui-table-fixed .layui-table-header table tr")[index]).height($(val).height());
        });
        //动态监听表体高度变化，冻结行跟着改变高度
        $(".layui-table-body  tr").resize(function () {
          $(".layui-table-body  tr").each(function (index, val) {
            $($(".layui-table-fixed .layui-table-body table tr")[index]).height($(val).height());
          });
        });
        //初始化高度，使得冻结行表体高度一致
        $(".layui-table-body  tr").each(function (index, val) {
          $($(".layui-table-fixed .layui-table-body table tr")[index]).height($(val).height());
        });

      }
      ,  height: 'full-83'
    });

    var $ = layui.$, active = {
      select: function () {
        var userName = $('#userName').val();
        var type = $('#type').val();
        table.reload('logList', {
          where: {
              userName: userName,
              type: type
          }
        });
      }
      ,del:function(){
          var checkStatus = table.checkStatus('logList')
                  , data = checkStatus.data;
          if (data.length ==0) {
              layer.msg('请选择要删除的数据', {icon: 5});
              return false;
          }
          var ids=[];
          for(item in data){
              ids.push(data[item].id);
          }
          del(ids);
        }
      ,add:function(){
        layer.open({
          id: 'form-add',
          type: 2,
          area: ['800px', '300px'],
          fix: false,
          maxmin: true,
          shadeClose: false,
          shade: 0.4,
          title: "添加签章",
          content: "/sys/sealManager/addSeal",
          end: function () {

            table.reload('logList',{});
          }


        });

      }
      ,reload:function(){
        $('#userName').val('');
       $('#type').val('');
        table.reload('logList', {
          where: {
              userName: null,
              type: null
          }
        });
      },
    };
    //监听工具条
    table.on('tool(log)', function (obj) {
      var data = obj.data;
      if (obj.event === 'del') {
          var ids=[];
          del(ids.push(data.id));
      }
    });

    $('.layui-col-md12 .layui-btn').on('click', function () {
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
    $('.select .layui-btn').on('click', function () {
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });

  });
  /**批量删除id*/
  function del(ids) {
    if(confirm("是否确认要删除?")) {
      $.ajax({
        url: "/sys/sealManager/deleteSeal",
        type: "post",
        data: {ids: ids},
        dataType: "json", traditional: true,
        success: function (data) {
          layer.msg(data.msg);
          layui.table.reload('logList');
        }
      });
    }

  }

  function search() {
    var  fileName=$("#fileName").val();
    var jsondata={
      fileName:fileName
    }
    layui.table.reload('logList', {where: jsondata});

  }

 function viewImage (a,b) {
    var url=b;
    var fileExtension = b.substring(b.lastIndexOf('.') + 1).toLowerCase();
      layer.open({
        type: 1
        ,
        offset: 't'
        ,
        id: 'layerDemoauto' //防止重复弹出
        ,
        area: ['600px', '600px']
        ,
        content: '<img width=\'100%\' height=\'100%\'  src="/supervisor/projectManager/img?fid=' + a + '" >'
        ,
        btn: '关闭'
        ,
        btnAlign: 'c' //按钮居中
        ,
        title: "图片详情"
        ,
        shade: 0.4//不显示遮罩
        ,
        yes: function () {
          layer.closeAll();
        }
      });

  }
</script>
</body>

</html>
